//
//  PackageDetailInfo.m
//  HxgProject
//
//  Created by 黄小刚 on 2018/7/8.
//  Copyright © 2018年 XMYY-19. All rights reserved.
//

#import "PackageDetailInfo.h"
#import "ApplyInfo.h"
#import "PayBackRecordInfo.h"

@implementation PackageDetailInfo

- (instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setupDataWithDic:dic];
    }
    return self;
}

- (void)setupDataWithDic:(NSDictionary *)dic {
    
    // 设置还款记录数据
    NSMutableArray *paybackArr = [[NSMutableArray alloc] init];
    NSArray *childrenArr = dic[@"children"];
    if (childrenArr.count > 0) {
        for (NSDictionary *childDic in childrenArr) {
            PayBackRecordInfo *payBackRecordInfo = [[PayBackRecordInfo alloc] initWithDic:childDic];
            [paybackArr addObject:payBackRecordInfo];
        }
    } else {
        PayBackRecordInfo *payBackRecordInfo = [[PayBackRecordInfo alloc] initWithDic:dic];
        [paybackArr addObject:payBackRecordInfo];
    }
    self.paybackRecordArr = paybackArr;
    
    self.applyInfo = [[ApplyInfo alloc] initWithDic:dic];
    
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
    NSLog(@"undefine key is :%@",key);
    
//    // 过滤状态字段
//    if ([key isEqualToString:@"children"]) {
//        NSArray *childArrs = (NSArray *)value;
//
//        int loanOperationInt = -1;
//        NSDictionary *tempDic = nil;
//        for (NSDictionary *dic in childArrs) {
//
//            int tempLoanOperation = 0;
//            if (!isEmptyString(dic[@"loanOperation"])) {
//                tempLoanOperation = [dic[@"loanOperation"] intValue];
//            }
//
//            if (tempLoanOperation > loanOperationInt) {
//                loanOperationInt = tempLoanOperation;
//                tempDic = dic;
//            }
//        }
//    }
}

- (NSString *)getOverTimeStr:(NSString *)str{
    NSString *returnStr = @"否";
    if ([str isEqualToString:@"Y"]) {
        returnStr = @"是";
    }
    return returnStr;
}

- (NSString *)getRepaymentStatusStr:(NSString *)loanOperationStr {
    NSString *stateStr = @"待审核";
    if ([loanOperationStr isEqualToString:@"4"]) {
        stateStr = @"已逾期";
    } else if ([loanOperationStr isEqualToString:@"3"]) {
        stateStr = @"已还清";
    }else if ([loanOperationStr isEqualToString:@"2"]) {
        stateStr = @"已放款";
    } else if ([loanOperationStr isEqualToString:@"1"]) {
        stateStr = @"待放款";
    }
    
    return stateStr;
}






@end
